package com.linksoul.mapper;

import com.linksoul.domain.UserResponse;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2025/05/01/17:11
 **/
@Mapper
public interface UserResponseMapper {
    @Insert("INSERT INTO soul_mbti.user_response (request_id, question_id, option_id, response_time) " +
            "VALUES (#{requestId}, #{questionId}, #{optionId}, #{responseTime})")
    @Options(useGeneratedKeys = true, keyProperty = "responseId")
    int insert(UserResponse response);

    @Insert({
            "<script>",
            "INSERT INTO soul_mbti.user_response (user_hash, question_id, option_id) VALUES ",
            "<foreach collection='responses' item='item' separator=','>",
            "(#{item.requestId}, #{item.questionId}, #{item.optionId})",
            "</foreach>",
            "</script>"
    })
    int batchInsert(@Param("responses") List<UserResponse> responses);
}
